<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/4/5
  Time: 19:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" errorPage="CookieLogin.jsp" %>
<%
    request.setCharacterEncoding("UTF-8");
    String username = "";
    int visitTimes = 0;
    Cookie[] cookies = request.getCookies();
    for(int i = 0; cookies != null && i < cookies.length; i++) {
        Cookie cookie = cookies[i];
        if ("username".equals(cookie.getName())) {
            username = cookie.getValue();
        } else if ("visitTimes".equals(cookie.getName())) {
            visitTimes = Integer.parseInt(cookie.getValue());
        }
    }
        if (username == null || username.trim().equals("")) {
            throw new Exception("您还没有登录,请登录!!");
        }

        Cookie visitTimesCookie = new Cookie("visitTimes",Integer.toString( ++visitTimes ));
        response.addCookie(visitTimesCookie);

%>
<html>
<head>
    <title>CookieTitle</title>
</head>
<body>
<div align="center" style="margin:0 auto;">
    <fieldset>
        <legend>登录信息</legend>
        <form action="CookieLogin.jsp" method="post">
            <table>
                <tr>
                    <td>您的账号是:</td>
                    <td><%=username%></td>
                </tr>
                <tr>
                    <td>登录次数:</td>
                    <td><%=visitTimes%></td>
                </tr>
                <tr>
                    <td>
                        <input type="button" value="refresh"
                               onclick="location='<%=request.getRequestURI() %>?ts='+new Date().getTime();"/>
                    </td>
                    <td><input type="submit" value="Link to Login Page"/></td>
                </tr>
            </table>
        </form>
    </fieldset>
    <div style="width: 400px;height:300px;margin: 0 auto;">
       <img src="images/70.jpg"><img src="images/71.jpg">
    </div>
</div>
</body>
</html>
